#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# @Time    : 2024/9/19 9:27
# @Author  : Tom_zc
import os
import sys
import logging
import json

BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
sys.path.append(BASE_DIR)
sys.path.append(os.path.join(BASE_DIR, "utils"))
logging.basicConfig(level=logging.INFO,
                    format="%(asctime)s  %(levelname)s:%(message)s")

from utils.obs_helper import ObsHelper
from utils.common import func_retry


class PipeLineLogHelper:
    def __init__(self, ak, sk, obs_endpoint, obs_bucket_name):
        self.obs_helper = ObsHelper(ak, sk, obs_endpoint)
        self.obs_bucket_name = obs_bucket_name

    @func_retry()
    def upload_obs(self, filename):
        self.obs_helper.get_object(self.obs_bucket_name, filename)


def main():
    ak = os.getenv("ak")
    sk = os.getenv("sk")
    obs_endpoint = os.getenv("obs_endpoint")
    obs_bucket_name = os.getenv("obs_bucket_name")
    filename = os.getenv("zip_filename")

    obsHelper = PipeLineLogHelper(ak, sk, obs_endpoint, obs_bucket_name)
    obsHelper.upload_obs(filename)

    result = {
        "file": "bigBag",
        "filename": "archive.tar.gz"
    }
    print(json.dumps(result))
    sys.exit(0)


if __name__ == '__main__':
    main()
